<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://lib.baomitu.com/jquery/3.6.0/jquery.js"></script>

</head>

<body>
    <button id="btn">click</button>
    <script>
        const baseUrl = "http://www.liulongbin.top:3006";

        /*   let p1 = new Promise((resolve, reject) => {
              $.ajax({
                  url: baseUrl + '/api/cmtlist',
                  success: function (res) {
                      resolve(res)
                  }
              })
          })
          p1.then(res => console.log(res)) */

        let request = (url, method = 'get', data) => {
            let urls = baseUrl + url;
            return new Promise((resolve, reject) => {
                $.ajax({
                    url: urls,
                    data: data,
                    type: method,
                    success: (res) => {
                        // console.log(res)
                        resolve(res)
                    }
                })
            })
        }

        let obj = {
            username: 'zs',
            content: '空你吉瓦'
        }
        let btn = document.querySelector("#btn");
        btn.onclick = async function () {
            /*   let data = await request('/api/cmtlist')
              console.log(data) */

            let data = await request("/api/addcmt", "post", obj)
            console.log(data)
        };

    </script>

</body>

</html>